package com.alibaba.simpleimage.render;
import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.RenderedOp;

import com.alibaba.simpleimage.util.ImageLog;
import com.alibaba.simpleimage.util.JAIRegisterHelper;


public class ImageCropHelper {

    static {
        JAIRegisterHelper.register();
    }
    protected static ImageLog log = ImageLog.getLog(ImageCropHelper.class);

    public static PlanarImage crop(PlanarImage src, CropParameter param) {
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(src);
        pb.add(param.getX());
        pb.add(param.getY());
        pb.add((float) param.getWidth());
        pb.add((float) param.getHeight());
        RenderedOp op = JAI.create("crop", pb);
        return op;
    }
}
